package bean

import "sync"

type Set struct {
	Mu    sync.RWMutex
	items map[string]struct{}
}

func NewSet() *Set {
	return &Set{items: make(map[string]struct{})}
}

func (s *Set) Add(item string) {
	defer s.Mu.Unlock()
	s.Mu.Lock()
	s.items[item] = struct{}{}
}

func (s *Set) Remove(item string) {
	defer s.Mu.Unlock()
	s.Mu.Lock()
	delete(s.items, item)
}

func (s *Set) Contains(item string) bool {
	_, exists := s.items[item]
	return exists
}

func (s *Set) Size() int {
	return len(s.items)
}

func (s *Set) Clear() {
	defer s.Mu.Unlock()
	s.Mu.Lock()
	s.items = make(map[string]struct{})
}
